package jblip.apps.clip.cmds;

import java.util.Enumeration;

import jblip.BlipClient;
import jblip.apps.clip.ClipPrinter;
import jblip.resources.Shortlink;

public class PollShortlinks extends ClipCommand {

  @Override
  public int getRequiredArgsCount() {
    return 0;
  }
  
  @Override
  public int getMaximumArgsCount() {
    return 0;
  }
  
  @Override
  public void execute(BlipClient client, String[] args) {
    Integer since = null;
    if (ClipCommand.hasProperty("since")) {
      since = Integer.parseInt(ClipCommand.getProperty("since"));
    }
    Integer limit = null;
    if (ClipCommand.hasProperty("limit")) {
      limit = Integer.parseInt(ClipCommand.getProperty("limit"));
    }

    Integer offset = null;
    if (ClipCommand.hasProperty("offset")) {
      offset = Integer.parseInt(ClipCommand.getProperty("offset"));
    }
    

    Enumeration<? extends Shortlink> links = client.pollShortlinks(since, limit, offset);

    if (client.getLastError() == null) {
      while (links.hasMoreElements()) {
        ClipPrinter.print(links.nextElement());
      }
    } else {
      System.out.println("ERROR: " + client.getLastError());
    }
  }

  @Override
  public String getName() {
    return "links";
  }

  @Override
  public String getUsageMessage() {
    return "";
  }

}
